package gs.wicket.app.shop;

import gs.wicket.app.account.Korisnik;
import gs.wicket.app.login.LogInPage;
import gs.wicket.app.product.AboutProduct;
import gs.wicket.app.product.Product;
import gs.wicket.app.product.ProductsPage;
import gs.wicket.app.session.GSSession;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PageableListView;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.model.Model;

public class Nakit extends ProductsPage{
	
	public Nakit(){
		GSSession gsSession = (GSSession) getSession();
		Korisnik k = gsSession.getLogovanKorisnik();
		if (k==null){
			setResponsePage(LogInPage.class);
		}

	PageableListView products = new PageableListView("products", getJewelryProducts(), 2) {

	     private static final long serialVersionUID = 1L;

		@Override
	      protected void populateItem(ListItem item) {
	        Product product = (Product) item.getModelObject();
	        item.add(new Label("name", product.getName()));
	        Image image = new Image("image", new Model(product.getImageURL()));
	        
	        
	        PageParameters pars = new PageParameters();
	        pars.add("name", product.getName());
	        BookmarkablePageLink moinfl1 = new BookmarkablePageLink("moinfl1", AboutProduct.class, pars);
	        moinfl1.add(image);
	        item.add(moinfl1);
	        
	        
	     
	        item.add(new Label("description", product.getDescription()));//
	        item.add(new Label("price", "<b>  " + product.getPrice()+ " EUR</b>").setEscapeModelStrings(false));

	        BookmarkablePageLink book =new BookmarkablePageLink("moinfl", AboutProduct.class, pars);
	        book.add(new Label("nakit.infos", getLangProperty("search.product.info")));
	        item.add(book);
	        

	        item.add(new Link("add", item.getModel()) {

				private static final long serialVersionUID = 1L;
				{
					add(new Label("nakit.add", getLangProperty("search.product.add")));
					}
			@Override
	          public void onClick() {
	            Product selected = (Product) getModelObject();
	            getCart().getProducts().add(selected);
	          }
	        });
	      }
	    };
	
	    add(products);
	    add(new PagingNavigator("navigator", products));
	    add(new Label("nakit.title", getLangProperty("nakit.title")));
	    add(new Label("nakit.message", getLangProperty("search.product.message")));
	    
	    
	}
}
